package com.yishe.framework.ui.easyui;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TreeNode<T>  {
	private String id;//节点id，对载入远程数据很重要。
	private String parentId;//父节点id
	private String text;//显示在节点的文本。
	private String iconCls = "icon-tree-";
	private boolean isDefaultIcon = true;
	private String state = "open";//：节点状态，'open' or 'closed'，默认为'open'。当设置为'closed'时，拥有子节点的节点将会从远程站点载入它们。
	private String checked = "false";//：表明节点是否被选择。
	private Map<String, Object> attributes = new HashMap<String, Object>();//：可以为节点添加的自定义属性。
	private List<TreeNode<T>> children;
	
	public TreeNode() {}
	
	public TreeNode(T element) {
		addAttributes(element.getClass().getName().toLowerCase(),element);
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getParentId() {
		return parentId;
	}
	public void setParentId(String parentId) {
		this.parentId = parentId;
	}
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	public String getIconCls() {
		return iconCls;
	}
	public void setIconCls(String iconCls) {
		if(iconCls == null || "".equals(iconCls)){
			this.isDefaultIcon = true;
		}else{
			this.isDefaultIcon = false;
			this.iconCls = iconCls;
		}
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public String getChecked() {
		return checked;
	}
	public void setChecked(String checked) {
		this.checked = checked;
	}
	public List<TreeNode<T>> getChildren() {
		return children;
	}
	public void setChildren(List<TreeNode<T>> children) {
		this.children = children;
		if(children == null || children.isEmpty() || (! isDefaultIcon)){
			return;
		}else{
			this.iconCls = "icon-tree+";
		}
	}
	public Map<String, Object> getAttributes() {
		return attributes;
	}
	public void addAttributes(String key,Object value) {
//		if(attributes.containsKey(getC)){
//			
//		}
		this.attributes.put(key, value);
	}
}
